Skip to content

feat(auth): request offline_access scope in device flow#21

Merged
hbrombeer merged 2 commits intomainfrom
feat/offline-access-scope
Apr 30, 2026
Merged

feat(auth): request offline_access scope in device flow#21
hbrombeer merged 2 commits intomainfrom
feat/offline-access-scope

Conversation

@hbrombeer
Copy link
Copy Markdown
Member

Summary

  • Add offline_access to the scope param in the device-authz request so Keycloak issues an offline refresh token instead of a session-idle-bound one.
  • Without this, after ~30min idle the next refresh fails and the CLI nukes the credential file — user has to grounds login again. Same UX broke for me today; this is the fix gh, kubectl oidc-login, etc. all use.

Verification

Live test against account.grounds.gg/realms/grounds with the same client + same user:

scope refresh_expires_in
openid 1800 (= SSO session-idle TTL)
openid offline_access 0 (offline token, governed by offline-session-max, default 30d)

offline_access is a default optional realm scope in Keycloak — no keycloak-clients.ts change needed.

Test plan

  • go test ./internal/auth/... — passes (new assertion that scope contains offline_access)
  • go vet ./... clean
  • Live token endpoint round-trip (above table)
  • Post-release: brew upgrade grounds && grounds login should survive a >30min idle

🤖 Generated with Claude Code

Without `offline_access` in the device-authz scope param, Keycloak
issues a refresh token bound to the SSO session-idle window
(realm default 30 minutes). After a short idle period the CLI's
next refresh fails and `FileTokenSource` deletes the credentials,
forcing a `grounds login` re-auth — a bad UX for an interactive
CLI.

Adding `offline_access` upgrades the refresh token to an offline
token whose lifetime is governed by the offline-session settings
(default 30 days), matching the behaviour every developer
expects from `gh`, `kubectl oidc-login`, etc.

Verified live: same client + same user
- scope=openid                  → refresh_expires_in=1800
- scope=openid offline_access   → refresh_expires_in=0 (offline)

`offline_access` is a default optional realm scope in Keycloak,
so no per-client wiring is needed in keycloak-clients.ts.
@hbrombeer hbrombeer merged commit 304931b into main Apr 30, 2026
5 checks passed
@hbrombeer hbrombeer deleted the feat/offline-access-scope branch April 30, 2026 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant